#include <iostream>
#include <pthread.h>
#include <unistd.h>


class Task
{
public:
    Task(int a, int b)
        :_a(a)
        ,_b(b)
    {}

    int Execute()
    {
        return _a + _b;
    }

private:
    int _a;
    int _b;
};

class Result
{
public:
    Result(int res)
        :_res(res)
    {}

    int GetResult()
    {
        return _res;
    }
    
    ~Result()
    {}
private:
    int _res;
};


void* run(void* args)
{
    Task* t = static_cast<Task*>(args);
    Result* res = new Result(t->Execute());
    std::cout << "run执行Task..." << std::endl;
    sleep(2);
    std::cout << "result: " << res->GetResult() << std::endl;
    
    return res;
}



int main()
{
    pthread_t tid;
    Task* t = new Task(2,3);
    
    int n = pthread_create(&tid, nullptr, run, (void*)t);

    Result* ret = nullptr;
    pthread_join(tid, (void**)&ret);
    std::cout << "回收成功，ret: " << ret->GetResult() << std::endl;

    return 0;
}